package com.hxh.learn.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.core.util.StrUtil;
import com.hxh.learn.model.SysPermissions;
import com.hxh.learn.mapper.SysPermissionsMapper;
import com.hxh.learn.model.SysUser;
import com.hxh.learn.service.ISysPermissionsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hxh.learn.vo.SysPermissionsSearchVo;
import com.hxh.learn.vo.SysUserSearchVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 系统权限 服务实现类
 * </p>
 *
 * @author hxh
 * @since 2023-03-02
 */
@Service
public class SysPermissionsServiceImpl extends ServiceImpl<SysPermissionsMapper, SysPermissions> implements ISysPermissionsService {
    @Resource
    private SysPermissionsMapper sysPermissionsMapper;

    @Override
    public Page<SysPermissions> queryPermissionsList(SysPermissionsSearchVo vo) {
        LambdaQueryWrapper<SysPermissions> lambdaQuery = Wrappers.lambdaQuery(SysPermissions.class);
        lambdaQuery.like(StrUtil.isNotBlank(vo.getName()), SysPermissions::getName, vo.getName())
                .eq(vo.getStatus()!=null, SysPermissions::getStatus, vo.getStatus())
                .ge(vo.getStartTime() != null, SysPermissions::getCreateTime, vo.getStartTime())
                .le(vo.getEndTime() != null, SysPermissions::getCreateTime, vo.getEndTime());
        Page<SysPermissions> page = new Page<>(vo.getPageNum(), vo.getPageSize());
        return sysPermissionsMapper.selectPage(page, lambdaQuery);
    }
}
